package com.ourygo.fileselect.bean;

import java.io.*;

import com.ourygo.fileselect.OurygoApplication;
import com.ourygo.fileselect.util.FilePermissionUtil;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import androidx.documentfile.provider.DocumentFile;

public class Files implements Comparable<Files> {

    //路径
    public static final int FILE_TYPE_PATH = 0;
    //文件
    public static final int FILE_TYPE_FILE = 1;
    //.cdb文件
    public static final int FILE_TYPE_CDB = 2;
    //.conf文件(卡表)
    public static final int FILE_TYPE_CONF = 3;
    //.zip文件(卡图压缩包)
    public static final int FILE_TYPE_CARD_PIC = 4;
    //.lua文件
    public static final int FILE_TYPE_LUA = 5;
    //.cjcd文件
    public static final int FILE_TYPE_ENDING = 6;
    //.zip文件
    public static final int FILE_TYPE_ZIP = 7;
    //.jpg  .png  .bpm  .jpeg文件
    public static final int FILE_TYPE_PIC = 8;
    //.txt文件
    public static final int FILE_TYPE_TXT = 9;
    //.ydk文件
    public static final int FILE_TYPE_YDK = 10;
    //.yse-set文件
    public static final int FILE_TYPE_YSE_SET = 11;
    //自定义后缀文件
    public static final int FILE_TYPE_CUSTOM = 100;

    private File file;
    private DocumentFile documentFile;
    private int type;

    @Override
    public int compareTo(Files p1) {
        // TODO: Implement this method
        return getName().compareTo(p1.getName());
    }


    public Files(File file) {
        setFile(file);
    }

    public Files(DocumentFile documentFile) {
        setDocumentFile(documentFile);
    }

    public Files(Activity context, String path) {
        if (FilePermissionUtil.isCheckFilePermission(path) && !path.endsWith("android/data") && !path.endsWith("Android/data"))
            setDocumentFile(FilePermissionUtil.getDocumentFile(context, path));
        else
            setFile(new File(path));
    }

    public String getName() {
        if (isNormalFile())
            return file.getName();
        else
            return documentFile.getName();
    }

    public boolean isDirectory() {
        if (isNormalFile())
            return file.isDirectory();
        else
            return documentFile.isDirectory();
    }

//	public void getAbsolutePath(){
//		if (isNormalFile())
//			return file.getAbsolutePath();
//		else
//			return documentFile.getUri();
//	}

    public void setFile(File file) {
        this.file = file;
    }

    public File getFile() {
        return file;
    }

//	public DocumentFile getDocumentFile() {
//		return documentFile;
//	}

    public void setDocumentFile(DocumentFile documentFile) {
        this.documentFile = documentFile;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public boolean isNormalFile() {
        return file != null;
    }

    public String getAbsolutePath() {
        if (isNormalFile())
            return file.getAbsolutePath();
        else
            return FilePermissionUtil.toFilePath(documentFile);
    }

    public String getParentPath() {
        if (isNormalFile())
            return file.getParent();
        else
            return FilePermissionUtil.toFilePath(documentFile.getParentFile());
    }
}
